package samples;

import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.widgets.*;

public class Snippet9 {

  
	  public void run() {
		    Display display = new Display();
		    Shell shell = new Shell(display);
		    createContents(shell);
		    shell.open();
		    while (!shell.isDisposed()) {
		      if (!display.readAndDispatch()) {
		        display.sleep();
		      }
		    }
		    display.dispose();
		  }

		  private void createContents(Composite parent) {
		    parent.setLayout(new FillLayout());

		    // Create the ScrolledComposite to scroll horizontally and vertically
		    ScrolledComposite sc = new ScrolledComposite(parent, SWT.H_SCROLL
		        | SWT.V_SCROLL);

		    // Create a child composite to hold the controls
		    Composite child = new Composite(sc, SWT.NONE);
		    child.setLayout(new FillLayout());

		    // Create the buttons
		    new Button(child, SWT.PUSH).setText("One");
		    new Button(child, SWT.PUSH).setText("Two");
		    /*
		     * // Set the absolute size of the child child.setSize(400, 400);
		     */
		    // Set the child as the scrolled content of the ScrolledComposite
		    sc.setContent(child);

		    // Set the minimum size
		    sc.setMinSize(400, 400);

		    // Expand both horizontally and vertically
		    sc.setExpandHorizontal(true);
		    sc.setExpandVertical(true);
		  }

		  public static void main(String[] args) {
			    Display display = new Display();
			    Shell shell = new Shell(display);
			    shell.setLayout(new FillLayout());
			    
			    List list = new List(shell,SWT.V_SCROLL|SWT.H_SCROLL);
			    for (int i = 0; i < 20; i++) {
			  list.add("Java is an Object Oriented Programming Language");
			    }
			    shell.setText("Show Scrollbar");
			    shell.open();
			  shell.setSize(200,150);
			    while (!shell.isDisposed()) {
			      if (!display.readAndDispatch()) {
			        display.sleep();
			      }
			    }
			    display.dispose();
			  }
}

